<template>
    <div class="player">
      <div id="player"></div>
    </div>
</template>

<script>
export default {
  name:"Player",
  data () {
    return {
      course_id:0,
      lesson_id:0,
    }
  },
  mounted(){
      this.token = this.$settings.token();
      this.check_user_login();

      this.course_id = this.$route.params.course;
      this.lesson_id = this.$route.params.lesson;

      // todo 根据课时ID获取课时信息

      this.polvy();
  },
  methods: {
    check_user_login(){
       if(!this.token){
          this.$confirm('对不起，您尚未登录请登录后继续操作, 是否继续?', '路飞学城', {
            confirmButtonText: '登录',
            cancelButtonText: '返回上一页',
            type: 'error'
          }).then(() => {
              this.$router.push("/user/login");
          }).catch(() => {
              this.$router.go(-1);
          });
          return false; // 阻止代码继续往下执行
      }
    },
    polvy(){
        let self = this;
        let player = polyvObject('#player').videoPlayer({
          wrap: '#player',
          width: document.documentElement.clientWidth-260, // 页面宽度
          height: document.documentElement.clientHeight,   // 页面高度
          vid: '506b011792d41f37482b722e1d53330c_5',
          playsafe: function(vid, next) {
            self.$axios.get(`${self.$settings.Host}/courses/polvy/${self.course_id}/${self.lesson_id}/`,{
                headers:{
                    Authorization: "jwt " + self.token,
                }
            }).then(response=>{
                next(response.data);
            }).catch(error=>{
                this.$mesasge.error("无法正常视频！");
            });
          }
        });
    }
  },
  computed: {
  }
}
</script>

<style scoped>
</style>
